package com.obs.demo.controller;

import com.obs.demo.common.result.Result;
import com.obs.demo.controller.vo.ObsVo;
import com.obs.demo.service.ObsService;
import com.obs.services.model.PostSignatureResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@RestController
@RequestMapping("/obs")
public class ObsController {

    @Autowired
    private ObsService ObsService;

    /**
     * 上传单个文件
     *
     * @param file  文件控件
     * @param model 上传的目录：可根据自己情况是否需要
     */
    @PostMapping(value = "/upload", consumes = "multipart/form-data")
    public Result<ObsVo> obsUpload(@RequestParam("file") MultipartFile file, @RequestParam("model") String model, HttpServletRequest request) {
        return ObsService.upLoadOne(file, model, request);
    }

    /**
     * 获取OBS信息，用于前端表单上传所需的信息
     */
    @GetMapping
    public Result<PostSignatureResponse> getObsFormInfo() {
        return new Result<>(200, "OK", ObsService.getObsFormInfo());
    }
}
